package net.huashitong.Project.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import jodd.util.StringUtil;
import net.huashitong.Project.entity.RelocatePlan;
import net.huashitong.Project.entity.RelocateProgress;
import net.huashitong.Project.filter.RelocatePlanFilter;
import net.huashitong.Project.filter.RelocateProgressFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RelocateProgressDao extends StringDao<RelocateProgress> {

    public List<RelocateProgress> queryByProjectId(String projectId){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.projectId=:projectId").setParam("projectId", projectId);
        query.append(" order by obj.dataTime Desc");
        return query.listResult();
    }


    /**
     * 查找最新数据
     * @param filter
     */
    public List<RelocateProgress> queryRelocateProgressByFilter(RelocateProgressFilter filter){
        GenericQuery query = createQuery("obj");
        if (StringUtil.isNotBlank(filter.getProjectId()))
            query.append(" and obj.projectId =:projectId").setParam("projectId",filter.getProjectId());
        if (StringUtil.isNotBlank(filter.getDataTime()))
            query.append(" and obj.dataTime =:dataTime").setParam("dataTime",filter.getDataTime());
        query.append(" order by obj.dataTime DESC");
        return  query.listResult();
    }

}
